{% include "header.html" %}

<div class="container">
    <div class="box box-info">
        <div class="box-header">
            <h4 class="box-title"><span class="fa fa-pencil-square-o"></span>信息修改</h4>
        </div>
        <div class="box-body">
            <form method="post" class="form-horizontal">
                <input type="hidden" name="stu_id" value="{{ stu.stu_id }}">
                <div class="form-group">
                    <label for="real_name" class="control-label col-lg-2 col-sm-2 col-xs-4">姓名</label>
                    <div class="col-lg-10 col-sm-10">
                        <input name="stu_name" id="real_name" class="form-control" placeholder="{{ stu.stu_name }}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="class" class="control-label col-lg-2 col-sm-2 col-xs-4">专业班级</label>
                    <div class="col-lg-10 col-sm-10">
                        <input name="stu_class" id="class" class="form-control" placeholder="{{ stu.stu_class }}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="tel" class="control-label col-lg-2 col-sm-2 col-xs-4">手机号</label>
                    <div class="col-lg-10 col-sm-10">
                        <input name="stu_tel" id="tel" class="form-control" placeholder="{{ stu.stu_tel }}" maxlength="11">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-12" style="margin-top: 5px;">
                        <button type="submit" class="btn btn-info btn-block">确认修改</button>
                    </div>
                </div>
            </form>
            {% include "sign.html" %}
        </div>
    </div>
</div>

<script>
    $('form').submit(function (e) {
        e.preventDefault();
        var name = $('#real_name').val().trim();
        var clz = $('#class').val().trim();
        var tel = $('#tel').val().trim();
        if (name === "" && clz === "" && tel === "") {
            console.log("没做任何修改，不能提交！");
            return;
        }
        if (tel !== "" && !/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(tel)) {
            alert("电话号码格式错误！");
            return;
        }

        $.post('/change', $(this).serialize(), function (data) {
            if (data.status) {
                alert('SUCCESS: 修改成功！');
                location.href = '/home'
            } else {
                alert('ERROR: 修改失败！'+data.msg);
            }
        });
    });
</script>

</body>
</html>